function reload(){
	Ext.getCmp('tabs').getActiveTab().panel.store.reload();
}

Ext.onReady(function(){
	vid = document.getElementById("vid").value;
	var tb = new Ext.Toolbar({ height:25});
	if(uid == ''){
		tb.add({
				text: '请登录',
				iconCls: '',
				handler: function(){
					createLoginWin(window.basePath);
				}
			},{
				
			}
		);
	}else{
		var menu = new Ext.menu.Menu({
	        items: [{
				text: 'Password',
				iconCls: 'password',
				handler: function(){
				}
			}]
		});
		tb.add({
				text: '设置',
				id : 'set',
				iconCls: 'setting',
				menu: menu 
			},'-',{
			    text: '登出',
				iconCls: 'logout',  
				handler: function(){
					var form = document.forms["main"];	
					form.action=window.basePath + "portal.do?m=logout";
					form.submit();
				}
			},'-',"当前用户：",{
				text:uid,
			    handler:function(){
			    }
			},'-',{
				text: '刷新',
				id : 'allRefresh',
				iconCls:'refresh',
				handler:function(){
					
				}
			},'-',{
				text: '帮助',
				id:'help',
				iconCls:'docs',
				handler:function(){
					var strURL = "";
					window.open(strURL, "", "width=900px, height=700px, left=0,top=0,toolbar=no, menubar=no, scrollbars=0, resizable=1, location=0, status=0");
				}
			}
		);
	}
	tb.render('toolbar');
	new Ext.Viewport({
		layout: 'border',
	    items: [{
			xtype: 'box',
			region: 'north',
			el: 'north',
			height: 60
		},{
			id:'tabs',
			xtype: 'tabpanel',
			region: 'center',
			deferredRender: false,
			activeTab: 0,
			items:[
				new Tab({title:'帐号列表',panel:new RecordGrid({id:'account'})})
			],
			listeners:{
				'tabchange':function(e){
					if(uid != '') e.getActiveTab().panel.store.reload();
				}
			}
		}]
	});
});


Tab = Ext.extend(Ext.Panel,{
	title:null,
	panel:null,
	constructor:function(config){
		Ext.apply(this,config);
		Tab.superclass.constructor.call(this, {
			title:this.title,
			layout:'fit',
			items:this.panel
		});
	}
	
});

RecordGrid = Ext.extend(Ext.grid.GridPanel,{
	id: null,
	store: null,
	cm: null,
	constructor:function(config){
		this.condition = {id:config.id};
		this.store = new Ext.data.Store({
			autoLoad: false,
		    baseParams: this.condition,
		    remoteSort:true,
			proxy: new Ext.data.HttpProxy({
				method: 'POST',
				url: window.basePath + "portal.do?m=getRecord"
			}),
			reader: new Ext.data.JsonReader({
				totalProperty: 'totalProperty',
				root: 'root',
				id: 'order'
			},[
				{name:'uid'},
				{name:'password'}
			])
		});
		this.cm = new Ext.grid.ColumnModel([
			new Ext.grid.RowNumberer(),
			{ dataIndex: 'uid',header: "UID", align: "center", width: 70},
			{ dataIndex: 'password', header: "密码", align: "center", width: 120 }
		]);
		Ext.apply(this,config);
		RecordGrid.superclass.constructor.call(this, {
		});
		this.on({'rowdblclick':rowClickFn});
		function rowClickFn(grid,rowIndex, e) 
	 	{	
			var record = grid.getSelectionModel().getSelected();
			if(record)
			{
				alert(record.get("uid") + "/" + record.get("password"));
	   		}
	    }
	}
});